using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using Dimok;
using ConfigOCR = Dimok.Config.imaging.OCR;
using Docs = Dimok.Documents;
//using OCRs = Dimok.Documents.Ocr;

namespace AcrobatObjects {
	/// <summary>
	/// Wrapper for static members from different classes
	/// </summary>
	public class RemotePdf : MarshalByRefObject {
		
		public static RemotePdf ActivateRemotePdf(string tcpPath){	return (RemotePdf)Activator.GetObject(typeof(RemotePdf),tcpPath);	}

		public byte[] FillWordForm(byte[] file,DataTable formTable){
			return new Docs.Word().FillForm(file,formTable);
		}
		public byte[] FillWordForm(byte[][] files,DataTable formTable){
			return new Docs.Word().FillForm(files,formTable);
		}
		public byte[] CombineWordToPDF(byte[][] files,DataTable formTable,bool pdfOutput){
			return new Docs.Word().FillForm(files,formTable,pdfOutput);
		}
		/*
		private byte[] CombineWordToPDF(byte[][] files,string connection,string sql){
			return Docs.Utilities.CombineWordToPDF(files,connection,sql);
		}
		*/
		/*
		public byte[] CombineToPDF(byte[][] files){
			return Docs.Utilities.CombineToPDF(files);
		}
		*/
		public byte[] AnyToPDF(byte[] files){
			return Docs.PDF.AnyToPDF(files);
		}

		public byte[] FillPDFForm(byte[][] filesIn,Hashtable fields) {
			return Docs.PDF.FillForm(filesIn,fields);
		}
		public byte[] FillPDFForm(byte[] fileIn,Hashtable fields) {
			return Docs.PDF.FillForm(fileIn,fields);
		}
		public byte[] CombinePDF(byte[][] pdfPages) {
			return Dimok.Documents.PDF.CombinePDF(pdfPages);
		}
		public byte[] GetPages(byte[] file,string pages) {
			return FileManager.GetBytesFromFile(Dimok.Documents.PDF.GetPages_Acrobat(file,pages),true);
		}
		public string[] GetText(byte[] file,string pages) {
			return GetText(file,(int[])new StringList(pages));
		}
		public string[] GetText(byte[] file,params int[] pages) {
			return Docs.PDF.GetText(file,0,0,2000,2000,pages);
		}
		public byte[] TiffToPDF(byte[] fileIn) {
			return Dimok.Documents.PDF.TiffToPDF(fileIn);
		}
		public byte[] PrepButtonTemplate(byte[] buttonTemplate,string buttonField,string actionWebPage,int flags) {
			return Docs.PDF.PrepButtonTemplate(buttonTemplate,buttonField,actionWebPage,flags);
		}
		public byte[] Decrypt(byte[] file,params int[] pageNumbers){
			return Docs.PDF.Decrypt(file,pageNumbers);
		}
		public DataTable  ReadForm(byte[] file,DataSet dsMatrix) {
			return Docs.PDF.ReadForm(file, dsMatrix);
		}
		public Hashtable AnalizeForm(byte[] pdf,DataTable tblFormMap) {
			Hashtable ht = new Hashtable();
			StringDictionary sd = Docs.Utilities.AnalyseForm(new Docs.Matrix(pdf),tblFormMap.Rows);
			foreach(string key in sd.Keys)
				ht.Add(key,sd[key]);
			return ht;
		}

		#region OcrTiffToPdf
		//public byte[] OcrTiffToPdf(byte[] file){return OcrTiffToPdf(file,ConfigOCR.Engine,ConfigOCR.Accuracy);}
		//public byte[] OcrTiffToPdf(byte[] file,string ocrEngine){return OcrTiffToPdf(file,ocrEngine,ConfigOCR.Accuracy);}
		//public byte[] OcrTiffToPdf(byte[] file,string ocrEngine,string accuracy) {
		//	Thread.CurrentThread.Priority = ThreadPriority.Lowest;
		//	if( ocrEngine == null || ocrEngine == "" )ocrEngine = ConfigOCR.Engine;
		//	switch( ocrEngine ) {
		//			//case "lead": return OCRs.LeadTools.OcrTifftoPDF(file);
		//		case "adlib": return OCRs.AdLib.Ocr(file,(accuracy == null || accuracy == "") ? ConfigOCR.Accuracy : accuracy);
		//		default: throw new Exception("Unknown OCR Engine["+ocrEngine+"].");
		//	}
		//}
		#endregion OcrTiffToPdf
	}
}